package components
{
	import UIFree.ObjectEvent;
	import UIFree.command.ICommand;
	import UIFree.command.uif_commandManager;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import UIUtils.uif_util;
	
	import classes.c_events;
	import classes.c_locale;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.Rectangle;
	
	public class c_component extends uif_ecomponent {
		public function c_component(parent: uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:Object='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			//name = genName();
			createComponents();
		}
		
		protected function genName(): String {
			return MD5.encrypt((Math.random() * 100000).toString());
		}
		
		protected function createComponents(): void {
		}
		
		public function get cl(): collages {
			return app as collages;
		}
		
		public function get workspace(): EventDispatcher {
			return cl.workspace;
		}
		
		public function remove(): void {
			if (parent) parent.removeChild(this);
		}
		
		protected function executeCommand(command: ICommand): void {
			cl.workspace.dispatchEvent(new ObjectEvent(uif_commandManager.EXECUTE, command));
		}
		
		public function globalToLocalRect(rect: Rectangle): Rectangle {
			var rect: Rectangle = rect.clone();
			rect.topLeft = globalToLocal(rect.topLeft);
			rect.bottomRight = globalToLocal(rect.bottomRight);
			return rect;
		}
		
		public function localToGlobalRect(rect: Rectangle): Rectangle {
			var rect: Rectangle = rect.clone();
			rect.topLeft = localToGlobal(rect.topLeft);
			rect.bottomRight = localToGlobal(rect.bottomRight);
			return rect;
		}
		
		public function get locale(): Object {
			return c_locale;
		}
	}
}